﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace XamlFoundation.Converters
{
    /// <summary>
    /// Value converter to convert a bool to a visibility
    /// </summary>
    public class BoolToVisbilityConverter : ValueConverterBase, IValueConverter
    {
        /// <summary>
        /// Gets or sets if the result should be inverted
        /// </summary>
        public bool Invert { get; set; }

        /// <summary>
        /// Gets or sets if the result should be inverted
        /// </summary>
        public bool UseHidden { get; set; }

        #region Implementation of IValueConverter

        /// <summary>
        /// See <see cref="IValueConverter.Convert" />
        /// </summary>
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is bool))
            {
                return DependencyProperty.UnsetValue;
            }

            if ((bool)value ^ Invert)
            {
                return Visibility.Visible;
            }

            return UseHidden ? Visibility.Hidden : Visibility.Collapsed;

        }

        /// <summary>
        /// See <see cref="IValueConverter.ConvertBack" />
        /// </summary>
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
